﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using CsGL.OpenGL;
using CsGL.Util;
using System.Diagnostics;
using System.Collections;


namespace BuildingDrawer
{
    public partial class Form1 : Form
    {
        // original var
        List<E_Point> point_list = new List<E_Point>();//store points<pre-processing>
        List<E_Element> element_list = new List<E_Element>();//store lines<pre-processing>
        List<List<E_Point>> lp_list = new List<List<E_Point>>();// store all points in a list<after-processing>
        List<List<E_Element>> le_list = new List<List<E_Element>>();// store all lines in a list<after-processing>

        // compress var
        List<E_PointFrame> l_point_frames = new List<E_PointFrame>();
        List<E_ElementFrame> l_element_frames = new List<E_ElementFrame>();
        //ArrayList timekeys = null;
        Boolean isLoadComp = false;
        Stopwatch watch = new Stopwatch();
        CommonMethod g_method = new CommonMethod();

        // public var
      //  List<E_Area> area_list = new List<E_Area>();//store areas<pre-processing>
       // List<E_Solid> solid_list = new List<E_Solid>();//store solid<pre-processing>
        MyOGLControl myOGLView;

        int point_count = 0;
        int element_count = 0;
        int test_count = 0;

        int timer_times = 0;
        int dif_times = -1;
        int status = 0;
        Timer procTimer;
        int screenX, screenY;
        int LastXPos, LastYPos;
        bool IsLBDown, IsRBDown;
        float xrot = 0.0f, yrot = 0.0f;
        float xtrans = 0.0f, ytrans = 0.0f;
        float scale = 1f;
        float x_average = 0f; float y_average = 0f; float z_average = 0f;
        bool canrotate = true;

        public Form1()
        {

            InitializeComponent();
            this.Text = "VFIFE.processor";
            RToolStripMenuItem.Enabled = false;
            toolStripButton8.Enabled = false;
            toolStripButton12.Enabled = false;
            toolStripButton5.Enabled = false;
            toolStripButton13.Enabled = false;
            toolStripSplitButton1.Enabled = false;
            toolStripButton14.Enabled = false;
            toolStripButton15.Enabled = false;
            toolStripButton16.Enabled = false;
            toolStripButton17.Enabled = false;
            toolStripButton18.Enabled = false;
            ((Control)this).MouseWheel += new MouseEventHandler(Form1_MouseWheel);

        }

        private void 退出qToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void 打开OToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            //OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.InitialDirectory = "c:\\";
            //openFileDialog.Filter = "文本文件|*.*|所有文件|*.*";
            //openFileDialog.RestoreDirectory = true;
            //openFileDialog.FilterIndex = 1;
            //if (openFileDialog.ShowDialog() == DialogResult.OK)//press OK
            //{
            //    element_list.Clear();//clear all lists first
            //   // area_list.Clear();
            //    point_list.Clear();
            //   // solid_list.Clear();

            //    if (this.Controls.Contains(myOGLView))
            //    {
            //        this.Controls.Remove(myOGLView);
            //    }

            //    //myOGLView = null;
            //    string path = openFileDialog.FileName;
            //    string[] file_content = File.ReadAllLines(path, Encoding.Default);//read file
            //    for (int i = 0; i < file_content.Length; i++)
            //    {
            //        string[] sArray = file_content[i].Split('\t');
            //        if (sArray[0] == "POINT")// element type is POINT
            //        {
            //            E_Point p = new E_Point(int.Parse(sArray[1]), float.Parse(sArray[2]), float.Parse(sArray[3]), float.Parse(sArray[4]));
            //            point_list.Add(p);
            //        }
            //        else if (sArray[0] == "LINE")// element type is LINE
            //        {
            //            E_Line l = new E_Line(int.Parse(sArray[1]), float.Parse(sArray[2]), float.Parse(sArray[3]), float.Parse(sArray[4]), float.Parse(sArray[5]), float.Parse(sArray[6]), float.Parse(sArray[7]));
            //            line_list.Add(l);
            //        }
            //        else if (sArray[0] == "AREA")//element type is AREA
            //        {
            //            E_Area a = new E_Area(int.Parse(sArray[1]), float.Parse(sArray[5]), float.Parse(sArray[6]), float.Parse(sArray[7]), float.Parse(sArray[2]), float.Parse(sArray[3]), float.Parse(sArray[4]), float.Parse(sArray[8]), float.Parse(sArray[9]), float.Parse(sArray[10]), float.Parse(sArray[11]), float.Parse(sArray[12]), float.Parse(sArray[13]));
            //            area_list.Add(a);
            //        }
            //        else if (sArray[0] == "SOLID") //element type is SOLID
            //        {
            //            E_Solid s = new E_Solid(int.Parse(sArray[1]), float.Parse(sArray[2]), float.Parse(sArray[3]), float.Parse(sArray[4]), float.Parse(sArray[5]), float.Parse(sArray[6]), float.Parse(sArray[7]), float.Parse(sArray[8]), float.Parse(sArray[9]), float.Parse(sArray[10]), float.Parse(sArray[11]), float.Parse(sArray[12]), float.Parse(sArray[13]), float.Parse(sArray[14]), float.Parse(sArray[15]), float.Parse(sArray[16]), float.Parse(sArray[17]), float.Parse(sArray[18]), float.Parse(sArray[19]), float.Parse(sArray[20]), float.Parse(sArray[21]), float.Parse(sArray[22]), float.Parse(sArray[23]), float.Parse(sArray[24]), float.Parse(sArray[25]));
            //            solid_list.Add(s);
            //        }

            //    }
            //    float x = 0f, y = 0f, z = 0f;
            //    for (int i = 0; i < point_list.Count; i++)
            //    {
            //        x += point_list[i].x;
            //        y += point_list[i].y;
            //        z += point_list[i].z;
            //    }
            //    x_average = x / point_list.Count;
            //    y_average = y / point_list.Count;
            //    z_average = z / point_list.Count;
            //    myOGLView = new MyOGLControl(point_list, line_list, area_list, solid_list);
            //    ((Control)this.myOGLView).MouseDown += new MouseEventHandler(myOGLView_MouseDown);
            //    ((Control)this.myOGLView).MouseMove += new MouseEventHandler(myOGLView_MouseMove);
            //    ((Control)this.myOGLView).MouseUp += new MouseEventHandler(myOGLView_MouseUp);
            //    //myOGLView.Anchor = AnchorStyles.Top;
            //    myOGLView.Dock = DockStyle.Fill;

            //    myOGLView.BringToFront();
            //    myOGLView.Parent = this;
            //    myOGLView.Name = "Kimi";
            //    myOGLView.Visible = true;
            //    this.Controls.Add(myOGLView);
            //}
        }
        private void myOGLView_MouseEnter(object sender, MouseEventArgs e)
        {
            this.myOGLView.Focus();
        }
        private void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            try
            {
                if (myOGLView.Bounds.Contains(e.Location)) //determine whether mouse is on control
                {
                    if (e.Delta > 0)
                    {
                        scale = scale + 0.01f;
                        myOGLView.ChangeScale(scale);
                        myOGLView.Invalidate();
                    }
                    else if (e.Delta < 0)
                    {
                        scale = scale - 0.01f;
                        myOGLView.ChangeScale(scale);
                        myOGLView.Invalidate();
                    }
                }
            }
            catch { }
        }
        private void myOGLView_MouseDown(object sender, MouseEventArgs e)
        {
            screenX = e.X;
            screenY = e.Y;

            LastXPos = screenX;
            LastYPos = screenY;
            if (e.Button == MouseButtons.Left)
            {
                IsLBDown = true;
            }
            if (e.Button == MouseButtons.Right)
            {
                IsRBDown = true;
            }

        }

        private void myOGLView_MouseMove(object sender, MouseEventArgs e)
        {

            if (IsRBDown)
            {
                int xPos, yPos;
                xPos = e.X;
                yPos = e.Y;

                xrot += (float)((yPos - LastYPos) / 5.0);
                yrot += (float)((xPos - LastXPos) / 5.0);

                LastXPos = xPos;
                LastYPos = yPos;
                myOGLView.Changexrot(xrot);
                myOGLView.Changeyrot(yrot);

                myOGLView.Invalidate();
            }
        }

        private void myOGLView_MouseUp(object sender, MouseEventArgs e)
        {

            if (IsLBDown)
            {
                xtrans += (float)((e.X - LastXPos) / 50);
                ytrans += (float)((LastYPos - e.Y) / 50);

                if (scale < 1)
                {
                    xtrans = xtrans * scale;
                    ytrans = ytrans * scale;
                }


                myOGLView.Changextrans(xtrans);
                myOGLView.Changeytrans(ytrans);
                myOGLView.Invalidate();
                IsLBDown = false;
            }

            IsRBDown = false;
            IsLBDown = false;

        }

        private void 导入结果ToolStripMenuItem_Click(object sender, EventArgs e)  //import node<after-processing>
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "E:\\平面单元数据\\平面单元数据";
            openFileDialog.Filter = "文本文件|*.*|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                MessageBox.Show("Importing node...Please wait");
                element_list.Clear();
               // area_list.Clear();
                point_list.Clear();
               // solid_list.Clear();
                point_count = 0;
                test_count = 0;
                if (this.Controls.Contains(myOGLView))
                {
                    this.Controls.Remove(myOGLView);
                }

                //myOGLView = null;
                string path = openFileDialog.FileName;
                string[] file_content = File.ReadAllLines(path, Encoding.Default);
                List<E_Point> newlist = new List<E_Point>();
                for (int i = 0; i < file_content.Length; i++)
                {
                    file_content[i] = file_content[i].Substring(2, file_content[i].Length - 2);
                    for (int j = 1; j < file_content[i].Length - 1; j++)
                    {
                        if ((file_content[i][j] == ' ') && (file_content[i][j - 1] == ' '))
                        {
                            file_content[i] = file_content[i].Remove(j, 1);//remove extra space
                        }
                    }
                    string[] sArray = file_content[i].Split(' ');
                    string[] sArraynext = file_content[i].Split(' ');
                    if (i < file_content.Length - 1)
                    {
                        string test = file_content[i + 1].Substring(2, file_content[i + 1].Length - 2);
                        for (int j = 1; j < test.Length - 1; j++)
                        {
                            if ((test[j] == ' ') && (test[j - 1] == ' '))
                            {
                                test = test.Remove(j, 1);
                            }
                        }
                        sArraynext = null;
                        sArraynext = test.Split(' ');
                    }

                    if (sArray[0] == "0.000000000000000E+000")// time is 0
                    {
                        int id = 0;
                        float x = 0.0f;
                        float y = 0.0f;
                        float z = 0.0f;


                        id = (int)g_method.JoStringToF(sArray[1]);
                        x = g_method.JoStringToF(sArray[2]);
                        y = g_method.JoStringToF(sArray[3]);
                        z = g_method.JoStringToF(sArray[4]);

                        E_Point p = new E_Point(id, x, y, z);
                        point_list.Add(p);
                        point_count++;
                        if (sArray[0] != sArraynext[0])
                        {
                            lp_list.Add(point_list);
                        }
                    }
                    else if (sArray[0] != "0.000000000000000E+000")// not 0 time
                    {
                        int id = 0;
                        float x = 0.0f;
                        float y = 0.0f;
                        float z = 0.0f;
                        id = (int)g_method.JoStringToF(sArray[1]);
                        x = g_method.JoStringToF(sArray[2]);
                        y = g_method.JoStringToF(sArray[3]);
                        z = g_method.JoStringToF(sArray[4]);
                        E_Point p = new E_Point(id, x, y, z);
                        test_count++;

                        if (test_count == point_count)
                        {
                            newlist.Add(p);
                            if ((p.x == 0.7) && (p.y == 0.4) && (p.z == 0.0))
                            {
                                int hehe = 0;
                            }

                            lp_list.Add(new List<E_Point>(newlist.ToArray()));//a single current time is finished,add one this point_list of current time to lp_list
                            newlist.Clear();
                            test_count = 0;
                        }
                        else
                        {
                            newlist.Add(p);//just add current point to current point_list
                        }
                    }
                }
                MessageBox.Show("已导入全部点坐标");
            }
        }

        private void 导入线结果ToolStripMenuItem_Click(object sender, EventArgs e)    //import element(line)
        {
            //string lastTime = "0.0000000000000000E+000";
            string currentTime = "0.000000000000000E+000";
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "E:\\平面单元数据\\平面单元数据";
            openFileDialog.Filter = "文本文件|*.*|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                MessageBox.Show("Importing element...Please wait");
                element_list.Clear();
                
                dif_times = 0;
                if (this.Controls.Contains(myOGLView))
                {
                    this.Controls.Remove(myOGLView);
                }

                string path = openFileDialog.FileName;
                string[] file_content = File.ReadAllLines(path, Encoding.Default);

                List<E_Element> newlist = new List<E_Element>();
                for (int i = 0; i < file_content.Length; i++)
                {
                    int type = 0;// 1 represent bar, 2 represent plat
                    file_content[i] = file_content[i].Substring(2, file_content[i].Length - 2);

                    //get the element type 
                    if (file_content[i][0] == 'p')
                    {
                        type = 2;
                    }
                    else if (file_content[i][0] == 'b')
                    {
                        type = 1;
                    }
                    int pos = file_content[i].IndexOf('.')-1;
                    file_content[i] = file_content[i].Substring(pos, file_content[i].Length - pos);
                    for (int j = 1; j < file_content[i].Length - 1; j++)
                    {
                        if ((file_content[i][j] == ' ') && (file_content[i][j - 1] == ' '))
                        {
                            file_content[i] = file_content[i].Remove(j, 1);// remove extra space
                        }
                    }
                    string[] sArray = file_content[i].Split(' ');

                    string[] sArraynext = file_content[i].Split(' ');
                    if (i < file_content.Length - 1)
                    {
                        string test = file_content[i + 1].Substring(2, file_content[i + 1].Length - 2);


                        for (int j = 1; j < test.Length - 1; j++)
                        {
                            if ((test[j] == ' ') && (test[j - 1] == ' '))
                            {
                                test = test.Remove(j, 1);
                            }
                        }
                        sArraynext = null;
                        sArraynext = test.Split(' ');
                        
                    }

                    //////////////////////////////
                    switch(type)
                    {
                        case 1:   //bar
                            {
                                int id = 0;
                                int id1 = 0;
                                int id2 = 0;
                                float x1 = 0.0f, y1 = 0.0f, z1 = 0.0f, x2 = 0.0f, y2 = 0.0f, z2 = 0.0f;
                                E_Point p1 = new E_Point(); E_Point p2 = new E_Point();
                                id = (int)g_method.JoStringToF(sArray[1]);
                                id1 = (int)g_method.JoStringToF(sArray[2]);
                                id2 = (int)g_method.JoStringToF(sArray[3]);
                              
                                test_count++;
                                for (int k = 0; k < lp_list[dif_times].Count; k++)
                                {
                                    if (id1 == lp_list[dif_times][k].id)
                                    {
                                        x1 = lp_list[dif_times][k].x;
                                        y1 = lp_list[dif_times][k].y;
                                        z1 = lp_list[dif_times][k].z;
                                        //  p1 = lp_list[test_count][k];
                                    }
                                    if (id2 == lp_list[dif_times][k].id)
                                    {
                                        x2 = lp_list[dif_times][k].x;
                                        y2 = lp_list[dif_times][k].y;
                                        z2 = lp_list[dif_times][k].z;
                                        // p2 = lp_list[test_count][k];
                                    }
                                }

                                E_Bar l = new E_Bar(id, id1, x1, y1, z1, id2, x2, y2, z2);
                                //    E_Line l = new E_Line(id, p1, p2);

                                if (currentTime!=sArraynext[1])//读完一个时间片
                                {
                                    newlist.Add(l);
                                    le_list.Add(new List<E_Element>(newlist.ToArray()));
                                    dif_times++;
                                    newlist.Clear();
                                    currentTime = sArraynext[1];
                                }
                                else
                                {
                                    newlist.Add(l);
                                }

                                break;

                            }
                        case 2: //plat
                            {
                                bool PlatError = false;
                                int cir = sArray.Length;
                                List<int> nodeIdList = new List<int>();
                                List<E_Point> nodeList = new List<E_Point>();
                                int id = 0; ;
                                for (int j = 0; j < cir; j++)
                                {
                                    nodeIdList.Add((int)g_method.JoStringToF(sArray[j]));
                                }

                                id = nodeIdList[0];
                                //nodeIdList.RemoveAt(0);
                                for (int j = 2; j < nodeIdList.Count; j++)
                                {
                                    for (int k = 0; k < lp_list[dif_times].Count; k++)
                                    {
                                        if (nodeIdList[j] == lp_list[dif_times][k].id)
                                        {
                                            nodeList.Add(lp_list[dif_times][k]);
                                            break;
                                        }
                                        if (k == lp_list[dif_times].Count)
                                        {
                                            PlatError = true;//找不到节点 应该是数据出错
                                        }
                                    }
                                }
                                if (PlatError)//数据出错 不储存当前plat  
                                { break; }
                                E_Plat p = new E_Plat(id, nodeList);
                                if (currentTime != sArraynext[1])//读完一个时间片
                                {
                                    newlist.Add(p);
                                    le_list.Add(new List<E_Element>(newlist.ToArray()));
                                    dif_times++;
                                    newlist.Clear();
                                    currentTime = sArraynext[1];
                                }
                                else
                                {
                                    newlist.Add(p);
                                }
                            break;
                            }
                        default: break;
                            
                    }              
                }


                myOGLView = new MyOGLControl(lp_list[0], le_list[0]);
                ((Control)this.myOGLView).MouseDown += new MouseEventHandler(myOGLView_MouseDown);
                ((Control)this.myOGLView).MouseMove += new MouseEventHandler(myOGLView_MouseMove);
                ((Control)this.myOGLView).MouseUp += new MouseEventHandler(myOGLView_MouseUp);

                //myOGLView.Anchor = AnchorStyles.Top;
                myOGLView.Dock = DockStyle.Fill;

                myOGLView.BringToFront();
                myOGLView.Parent = this;
                myOGLView.Name = "Kimi";
                myOGLView.Visible = true;
                this.Controls.Add(myOGLView);
                RToolStripMenuItem.Enabled = true;
                toolStripButton8.Enabled = true;
                toolStripButton12.Enabled = true;
                toolStripButton5.Enabled = true;
                toolStripButton13.Enabled = true;
                toolStripSplitButton1.Enabled = true;
                toolStripButton14.Enabled = true;
                toolStripButton15.Enabled = true;
                toolStripButton16.Enabled = true;
                toolStripButton17.Enabled = true;
                toolStripButton18.Enabled = true;
            }

        }

        private void 运行ToolStripMenuItem_Click(object sender, EventArgs e)// click run
        {
            if (status == 0)//
            {
                toolStripButton5.Image = imageList1.Images[0];
                procTimer = new Timer();



                if (timesFasterToolStripMenuItem.Checked == true)
                {
                    procTimer.Interval = 1;
                    procTimer.Tick += new EventHandler(procTimer_Tick2);
                }
                if (timesFasterToolStripMenuItem1.Checked == true)
                {
                    procTimer.Interval = 1;
                    procTimer.Tick += new EventHandler(procTimer_Tick4);
                }
                if (normalToolStripMenuItem.Checked == true)
                {
                    procTimer.Interval = 1;
                    procTimer.Tick += new EventHandler(procTimer_Tick);
                }
                if (timesSlowerToolStripMenuItem.Checked == true)
                {
                    procTimer.Interval = 2;
                    procTimer.Tick += new EventHandler(procTimer_Tick);
                }
                if (timesSlowerToolStripMenuItem1.Checked == true)
                {
                    procTimer.Interval = 4;
                    procTimer.Tick += new EventHandler(procTimer_Tick);
                }
                procTimer.Start();
                status = 1;
            }
            else
            {
                toolStripButton5.Image = imageList1.Images[1];
                procTimer.Stop();
                status = 0;
            }


        }
        private void procTimer_Tick(object sender, EventArgs e)
        {
            if (!isLoadComp) //origin data
            {
                if (timer_times >= lp_list.Count)//finish drawing
                {
                    timer_times = 0;
                    procTimer.Stop();
                    toolStripButton5.Image = imageList1.Images[1];
                    status = 0;
                }
                else// not finish, keep update drawing till time finishes
                {
                    myOGLView.UpdateOGLList(lp_list[timer_times], le_list[timer_times]);

                    myOGLView.Invalidate();
                    timer_times++;
                }
            }
            // compress data
            else
            {
                if (timer_times >= l_point_frames.Count)// lp_list.Count)
                {
                    timer_times = 0;
                    procTimer.Stop();
                    toolStripButton5.Image = imageList1.Images[1];
                    status = 0;
                }
                else
                {

                 //   myOGLView.UpdateOGLList(l_point_frames[timer_times], l_line_frames[timer_times], area_list, solid_list);
                    //  myOGLView.glDraw();
                    myOGLView.Invalidate();
                    timer_times++;
                }
            }
        }
        private void procTimer_Tick2(object sender, EventArgs e)
        {
            if (!isLoadComp) //origin data
            {
                if (timer_times >= lp_list.Count)//finish drawing
                {
                    timer_times = 0;
                    procTimer.Stop();
                    toolStripButton5.Image = imageList1.Images[1];
                    status = 0;
                }
                else// not finish, keep update drawing till time finishes
                {
                    myOGLView.UpdateOGLList(lp_list[timer_times], le_list[timer_times]);

                    myOGLView.Invalidate();
                    timer_times += 2;
                }
            }
            // compress data
            else
            {
                if (timer_times >= l_point_frames.Count)// lp_list.Count)
                {
                    timer_times = 0;
                    procTimer.Stop();
                    toolStripButton5.Image = imageList1.Images[1];
                    status = 0;
                }
                else
                {

                    //myOGLView.UpdateOGLList(l_point_frames[timer_times], l_line_frames[timer_times], area_list, solid_list);
                    //  myOGLView.glDraw();
                    myOGLView.Invalidate();
                    timer_times += 2;
                }
            }
        }
        private void procTimer_Tick4(object sender, EventArgs e)
        {
            if (!isLoadComp) //origin data
            {
                if (timer_times >= lp_list.Count)//finish drawing
                {
                    timer_times = 0;
                    procTimer.Stop();
                    toolStripButton5.Image = imageList1.Images[1];
                    status = 0;
                }
                else// not finish, keep update drawing till time finishes
                {
                    myOGLView.UpdateOGLList(lp_list[timer_times], le_list[timer_times]);

                    myOGLView.Invalidate();
                    timer_times += 4;
                }
            }
            // compress data
            else
            {
                if (timer_times >= l_point_frames.Count)// lp_list.Count)
                {
                    timer_times = 0;
                    procTimer.Stop();
                    toolStripButton5.Image = imageList1.Images[1];
                    status = 0;
                }
                else
                {

                   // myOGLView.UpdateOGLList(l_point_frames[timer_times], l_line_frames[timer_times], area_list, solid_list);
                    //  myOGLView.glDraw();
                    myOGLView.Invalidate();
                    timer_times += 4;
                }
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)// import node from toolbal
        {
            //OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.InitialDirectory = "c:\\";
            //openFileDialog.Filter = "文本文件|*.*|所有文件|*.*";
            //openFileDialog.RestoreDirectory = true;
            //openFileDialog.FilterIndex = 1;
            //if (openFileDialog.ShowDialog() == DialogResult.OK)
            //{
            //    //MessageBox.Show("Importing node...Please wait");
            //    line_list.Clear();
            //    area_list.Clear();
            //    point_list.Clear();
            //    solid_list.Clear();
            //    point_count = 0;
            //    test_count = 0;
            //    if (this.Controls.Contains(myOGLView))
            //    {
            //        this.Controls.Remove(myOGLView);
            //    }

            //    //myOGLView = null;
            //    string path = openFileDialog.FileName;
            //    string[] file_content = File.ReadAllLines(path, Encoding.Default);
            //    List<E_Point> newlist = new List<E_Point>();
            //    for (int i = 0; i < file_content.Length; i++)
            //    {
            //        file_content[i] = file_content[i].Substring(2, file_content[i].Length - 2);
            //        //  file_content[i].Replace("  ", " ");

            //        for (int j = 1; j < file_content[i].Length - 1; j++)
            //        {
            //            if ((file_content[i][j] == ' ') && (file_content[i][j - 1] == ' '))
            //            {
            //                file_content[i] = file_content[i].Remove(j, 1);
            //            }
            //        }
            //        string[] sArray = file_content[i].Split(' ');
            //        string[] sArraynext = file_content[i].Split(' ');
            //        if (i < file_content.Length - 1)
            //        {
            //            string test = file_content[i + 1].Substring(2, file_content[i + 1].Length - 2);
            //            for (int j = 1; j < test.Length - 1; j++)
            //            {
            //                if ((test[j] == ' ') && (test[j - 1] == ' '))
            //                {
            //                    test = test.Remove(j, 1);
            //                }
            //            }
            //            sArraynext = null;
            //            sArraynext = test.Split(' ');
            //        }

            //        if (sArray[0] == "0.0000000000000000e+000")//0 time
            //        {
            //            int id = 0;
            //            float x = 0.0f;
            //            float y = 0.0f;
            //            float z = 0.0f;
            //            if (sArray[1][22] == '0')  //id<10
            //            {
            //                id = int.Parse(sArray[1][0].ToString());                   //get first data of this line
            //            }
            //            else if (sArray[1][22] == '1')//10~100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 10 + int.Parse(sArray[1][2].ToString());
            //            }
            //            else if (sArray[1][22] == '2')//>100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 100 + int.Parse(sArray[1][2].ToString()) * 10 + int.Parse(sArray[1][3].ToString());
            //            }

            //            if (sArray[2][0] == '-')    //x is negative
            //            {
            //                if (sArray[2][20] == '+')         // positive power
            //                {
            //                    int times = int.Parse(sArray[2][23].ToString());
            //                    x = float.Parse(sArray[2].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[2][23].ToString()) * (-1);
            //                    x = float.Parse(sArray[2].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //            }
            //            else                   //x is positive
            //            {
            //                if (sArray[2][19] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[2][22].ToString());
            //                    x = float.Parse(sArray[2].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[2][22].ToString()) * (-1);
            //                    x = float.Parse(sArray[2].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //            }

            //            if (sArray[3][0] == '-')    //y is negative
            //            {
            //                if (sArray[3][20] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[3][23].ToString());
            //                    y = float.Parse(sArray[3].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[3][23].ToString()) * (-1);
            //                    y = float.Parse(sArray[3].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //            }
            //            else                   //y is positive
            //            {
            //                if (sArray[3][19] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[3][22].ToString());
            //                    y = float.Parse(sArray[3].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[3][22].ToString()) * (-1);
            //                    y = float.Parse(sArray[3].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //            }

            //            if (sArray[4][0] == '-')    //z is negative
            //            {
            //                if (sArray[4][20] == '+')         //positve power
            //                {
            //                    int times = int.Parse(sArray[4][23].ToString());
            //                    z = float.Parse(sArray[4].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[4][23].ToString()) * (-1);
            //                    z = float.Parse(sArray[4].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //            }
            //            else                   //z is positive
            //            {
            //                if (sArray[4][19] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[4][22].ToString());
            //                    z = float.Parse(sArray[4].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[4][22].ToString()) * (-1);
            //                    z = float.Parse(sArray[4].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //            }

            //            E_Point p = new E_Point(id, x, y, z);
            //            point_list.Add(p);
            //            point_count++;
            //            if (sArray[0] != sArraynext[0])
            //            {
            //                lp_list.Add(point_list);
            //            }
            //        }
            //        else if (sArray[0] != "0.0000000000000000e+000")// not 0 time
            //        {
            //            int id = 0;
            //            float x = 0.0f;
            //            float y = 0.0f;
            //            float z = 0.0f;
            //            if (sArray[1][22] == '0')  //id<10
            //            {
            //                id = int.Parse(sArray[1][0].ToString());                   //get first data of this line
            //            }
            //            else if (sArray[1][22] == '1')//10~100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 10 + int.Parse(sArray[1][2].ToString());
            //            }
            //            else if (sArray[1][22] == '2')//>100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 100 + int.Parse(sArray[1][2].ToString()) * 10 + int.Parse(sArray[1][3].ToString());
            //            }

            //            if (sArray[2][0] == '-')    //x is negative
            //            {
            //                if (sArray[2][20] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[2][23].ToString());
            //                    x = float.Parse(sArray[2].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[2][23].ToString()) * (-1);
            //                    x = float.Parse(sArray[2].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //            }
            //            else                   //x is positive
            //            {
            //                if (sArray[2][19] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[2][22].ToString());
            //                    x = float.Parse(sArray[2].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[2][22].ToString()) * (-1);
            //                    x = float.Parse(sArray[2].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //            }

            //            if (sArray[3][0] == '-')    //y is negative
            //            {
            //                if (sArray[3][20] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[3][23].ToString());
            //                    y = float.Parse(sArray[3].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[3][23].ToString()) * (-1);
            //                    y = float.Parse(sArray[3].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //            }
            //            else                   //y is positive
            //            {
            //                if (sArray[3][19] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[3][22].ToString());
            //                    y = float.Parse(sArray[3].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[3][22].ToString()) * (-1);
            //                    y = float.Parse(sArray[3].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //            }

            //            if (sArray[4][0] == '-')    //z is negative
            //            {
            //                if (sArray[4][20] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[4][23].ToString());
            //                    z = float.Parse(sArray[4].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[4][23].ToString()) * (-1);
            //                    z = float.Parse(sArray[4].Substring(0, 18)) * (float)Math.Pow(10, times);
            //                }
            //            }
            //            else                   //z is positive
            //            {
            //                if (sArray[4][19] == '+')         //positive power
            //                {
            //                    int times = int.Parse(sArray[4][22].ToString());
            //                    z = float.Parse(sArray[4].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //                else                          //negative power
            //                {
            //                    int times = int.Parse(sArray[4][22].ToString()) * (-1);
            //                    z = float.Parse(sArray[4].Substring(0, 17)) * (float)Math.Pow(10, times);
            //                }
            //            }

            //            E_Point p = new E_Point(id, x, y, z);
            //            test_count++;

            //            if (test_count == point_count)
            //            {
            //                newlist.Add(p);
            //                lp_list.Add(new List<E_Point>(newlist.ToArray()));
            //                newlist.Clear();
            //                test_count = 0;
            //            }
            //            else
            //            {
            //                newlist.Add(p);
            //            }
            //        }
            //    }
            //    NodeComp(path);
            //    MessageBox.Show("已导入全部点坐标");
            //}
        }//import node from toolbar

        private void toolStripButton11_Click(object sender, EventArgs e)// import element(line)from toolbar
        {
            //OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.InitialDirectory = "c:\\";
            //openFileDialog.Filter = "文本文件|*.*|所有文件|*.*";
            //openFileDialog.RestoreDirectory = true;
            //openFileDialog.FilterIndex = 1;
            //if (openFileDialog.ShowDialog() == DialogResult.OK)
            //{
            //    //MessageBox.Show("Importing element...Please wait");
            //    line_list.Clear();
            //    line_count = 0;
            //    test_count = 0;
            //    dif_times = 0;
            //    if (this.Controls.Contains(myOGLView))
            //    {
            //        this.Controls.Remove(myOGLView);
            //    }

            //    string path = openFileDialog.FileName;
            //    string[] file_content = File.ReadAllLines(path, Encoding.Default);

            //    List<E_Line> newlist = new List<E_Line>();
            //    for (int i = 0; i < file_content.Length; i++)
            //    {
            //        file_content[i] = file_content[i].Substring(2, file_content[i].Length - 2);
            //        for (int j = 1; j < file_content[i].Length - 1; j++)
            //        {
            //            if ((file_content[i][j] == ' ') && (file_content[i][j - 1] == ' '))
            //            {
            //                file_content[i] = file_content[i].Remove(j, 1);// remove extra space
            //            }
            //        }
            //        string[] sArray = file_content[i].Split(' ');

            //        string[] sArraynext = file_content[i].Split(' ');
            //        if (i < file_content.Length - 1)
            //        {
            //            string test = file_content[i + 1].Substring(2, file_content[i + 1].Length - 2);


            //            for (int j = 1; j < test.Length - 1; j++)
            //            {
            //                if ((test[j] == ' ') && (test[j - 1] == ' '))
            //                {
            //                    test = test.Remove(j, 1);
            //                }
            //            }
            //            sArraynext = null;
            //            sArraynext = test.Split(' ');
            //        }


            //        if (sArray[0] == "0.0000000000000000e+000")
            //        {
            //            int id = 0;
            //            int id1 = 0;
            //            int id2 = 0;

            //            E_Point p1 = new E_Point(); E_Point p2 = new E_Point();
            //            if (sArray[1][22] == '0')  //id<10
            //            {
            //                id = int.Parse(sArray[1][0].ToString());                   //get first data
            //            }
            //            else if (sArray[1][22] == '1')//10~100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 10 + int.Parse(sArray[1][2].ToString());
            //            }
            //            else if (sArray[1][22] == '2')//>100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 100 + int.Parse(sArray[1][2].ToString()) * 10 + int.Parse(sArray[1][3].ToString());
            //            }

            //            if (sArray[2][22] == '0')  //id<10
            //            {
            //                id1 = int.Parse(sArray[2][0].ToString());                   //get first data
            //            }
            //            else if (sArray[2][22] == '1')//10~100
            //            {
            //                id1 = int.Parse(sArray[2][0].ToString()) * 10 + int.Parse(sArray[2][2].ToString());
            //            }
            //            else if (sArray[2][22] == '2')//>100
            //            {
            //                id1 = int.Parse(sArray[2][0].ToString()) * 100 + int.Parse(sArray[2][2].ToString()) * 10 + int.Parse(sArray[2][3].ToString());
            //            }

            //            if (sArray[3][22] == '0')  //id<10
            //            {
            //                id2 = int.Parse(sArray[3][0].ToString());                   //get first data of this line
            //            }
            //            else if (sArray[3][22] == '1')//10~100
            //            {
            //                id2 = int.Parse(sArray[3][0].ToString()) * 10 + int.Parse(sArray[3][2].ToString());
            //            }
            //            else if (sArray[3][22] == '2')//>100
            //            {
            //                id2 = int.Parse(sArray[3][0].ToString()) * 100 + int.Parse(sArray[3][2].ToString()) * 10 + int.Parse(sArray[3][3].ToString());
            //            }
            //            for (int k = 0; k < point_list.Count; k++)
            //            {
            //                if (id1 == point_list[k].id)
            //                {
            //                    //x1 = point_list[k].x;
            //                    //y1 = point_list[k].y;
            //                    //z1 = point_list[k].z;
            //                    p1 = point_list[k];
            //                }
            //                if (id2 == point_list[k].id)
            //                {
            //                    //x2 = point_list[k].x;
            //                    //y2 = point_list[k].y;
            //                    //z2 = point_list[k].z;
            //                    p2 = point_list[k];
            //                }
            //            }

            //            E_Line l = new E_Line(id, p1, p2);
            //            line_list.Add(l);
            //            line_count++;
            //            if (sArray[0] != sArraynext[0])
            //            {
            //                ll_list.Add(line_list);
            //            }
            //        }
            //        else
            //        {
            //            int id = 0;
            //            int id1 = 0;
            //            int id2 = 0;
            //            float x1 = 0.0f, y1 = 0.0f, z1 = 0.0f, x2 = 0.0f, y2 = 0.0f, z2 = 0.0f;
            //            E_Point p1 = new E_Point(); E_Point p2 = new E_Point();
            //            if (sArray[1][22] == '0')  //id<10
            //            {
            //                id = int.Parse(sArray[1][0].ToString());                   //get first data of this line
            //            }
            //            else if (sArray[1][22] == '1')//10~100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 10 + int.Parse(sArray[1][2].ToString());
            //            }
            //            else if (sArray[1][22] == '2')//>100
            //            {
            //                id = int.Parse(sArray[1][0].ToString()) * 100 + int.Parse(sArray[1][2].ToString()) * 10 + int.Parse(sArray[1][3].ToString());
            //            }

            //            if (sArray[2][22] == '0')  //id>10
            //            {
            //                id1 = int.Parse(sArray[2][0].ToString());                   //get first data of this line
            //            }
            //            else if (sArray[2][22] == '1')//10~100
            //            {
            //                id1 = int.Parse(sArray[2][0].ToString()) * 10 + int.Parse(sArray[2][2].ToString());
            //            }
            //            else if (sArray[2][22] == '2')//>100
            //            {
            //                id1 = int.Parse(sArray[2][0].ToString()) * 100 + int.Parse(sArray[2][2].ToString()) * 10 + int.Parse(sArray[2][3].ToString());
            //            }

            //            if (sArray[3][22] == '0')  //id<10
            //            {
            //                id2 = int.Parse(sArray[3][0].ToString());                   //get first data of this line
            //            }
            //            else if (sArray[3][22] == '1')//10~100
            //            {
            //                id2 = int.Parse(sArray[3][0].ToString()) * 10 + int.Parse(sArray[3][2].ToString());
            //            }
            //            else if (sArray[3][22] == '2')//>100
            //            {
            //                id2 = int.Parse(sArray[3][0].ToString()) * 100 + int.Parse(sArray[3][2].ToString()) * 10 + int.Parse(sArray[3][3].ToString());
            //            }
            //            test_count++;
            //            for (int k = 0; k < lp_list[dif_times].Count; k++)
            //            {
            //                if (id1 == lp_list[dif_times][k].id)
            //                {
            //                    x1 = lp_list[dif_times][k].x;
            //                    y1 = lp_list[dif_times][k].y;
            //                    z1 = lp_list[dif_times][k].z;
            //                    //  p1 = lp_list[test_count][k];
            //                }
            //                if (id2 == lp_list[dif_times][k].id)
            //                {
            //                    x2 = lp_list[dif_times][k].x;
            //                    y2 = lp_list[dif_times][k].y;
            //                    z2 = lp_list[dif_times][k].z;
            //                    // p2 = lp_list[test_count][k];
            //                }
            //            }

            //            E_Line l = new E_Line(id, id1, x1, y1, z1, id2, x2, y2, z2);
            //            //    E_Line l = new E_Line(id, p1, p2);

            //            if (test_count == line_count)
            //            {
            //                newlist.Add(l);
            //                ll_list.Add(new List<E_Line>(newlist.ToArray()));
            //                dif_times++;
            //                newlist.Clear();
            //                test_count = 0;
            //            }
            //            else
            //            {
            //                newlist.Add(l);
            //            }
            //        }
            //    }

            //    ElementComp(path);


            //    myOGLView = new MyOGLControl(lp_list[0], ll_list[0], area_list, solid_list);
            //    ((Control)this.myOGLView).MouseDown += new MouseEventHandler(myOGLView_MouseDown);
            //    ((Control)this.myOGLView).MouseMove += new MouseEventHandler(myOGLView_MouseMove);
            //    ((Control)this.myOGLView).MouseUp += new MouseEventHandler(myOGLView_MouseUp);

            //    //myOGLView.Anchor = AnchorStyles.Top;
            //    myOGLView.Dock = DockStyle.Fill;

            //    myOGLView.BringToFront();
            //    myOGLView.Parent = this;
            //    myOGLView.Name = "Kimi";
            //    myOGLView.Visible = true;
            //    this.Controls.Add(myOGLView);
            //    RToolStripMenuItem.Enabled = true;
            //    toolStripButton8.Enabled = true;
            //    toolStripButton12.Enabled = true;
            //    toolStripButton5.Enabled = true;
            //    toolStripButton13.Enabled = true;
            //    toolStripSplitButton1.Enabled = true;
            //    toolStripButton14.Enabled = true;
            //    toolStripButton15.Enabled = true;
            //    toolStripButton16.Enabled = true;
            //    toolStripButton17.Enabled = true;
            //    toolStripButton18.Enabled = true;
            //}
        }//import element from toolbar

        private void toolStripButton5_Click(object sender, EventArgs e)//click run in toolbar
        {
            if (status == 0)
            {
                toolStripButton5.Image = imageList1.Images[0];
                procTimer = new Timer();

                if (timesFasterToolStripMenuItem.Checked == true)
                {
                    procTimer.Interval = 1;
                    procTimer.Tick += new EventHandler(procTimer_Tick2);
                }
                if (timesFasterToolStripMenuItem1.Checked == true)
                {
                    procTimer.Interval = 1;
                    procTimer.Tick += new EventHandler(procTimer_Tick4);
                }
                if (normalToolStripMenuItem.Checked == true)
                {
                    procTimer.Interval = 1;
                    procTimer.Tick += new EventHandler(procTimer_Tick);
                }
                if (timesSlowerToolStripMenuItem.Checked == true)
                {
                    procTimer.Interval = 2;
                    procTimer.Tick += new EventHandler(procTimer_Tick);
                }
                if (timesSlowerToolStripMenuItem1.Checked == true)
                {
                    procTimer.Interval = 4;
                    procTimer.Tick += new EventHandler(procTimer_Tick);
                }
                procTimer.Start();
                status = 1;
            }
            else
            {
                toolStripButton5.Image = imageList1.Images[1];
                procTimer.Stop();
                status = 0;
            }
        }

        private void toolStripButton13_Click(object sender, EventArgs e)//click return to original state in toolbar
        {
            //if (!isLoadComp)
            //{
            //    if (lp_list.Count != 0)
            //    {
            //        myOGLView.UpdateOGLList(lp_list[0], ll_list[0], area_list, solid_list);
            //    }
            //}
            //else
            //{
            //    if (l_point_frames.Count != 0)
            //    {
            //        myOGLView.UpdateOGLList(l_point_frames[0], l_line_frames[0], area_list, solid_list);
            //    }
            //}

            ////  myOGLView.glDraw();
            //myOGLView.Invalidate();
        }

        private void timesFasterToolStripMenuItem_Click(object sender, EventArgs e)//run at 2 times faster speed
        {
            procTimer = new Timer();
            procTimer.Interval = 1;
            timesFasterToolStripMenuItem.Checked = true;
            timesFasterToolStripMenuItem1.Checked = false;
            normalToolStripMenuItem.Checked = false;
            timesSlowerToolStripMenuItem.Checked = false;
            timesSlowerToolStripMenuItem1.Checked = false;
        }

        private void timesFasterToolStripMenuItem1_Click(object sender, EventArgs e)//run at 4 times faster speed
        {
            procTimer = new Timer();
            procTimer.Interval = 1;
            timesFasterToolStripMenuItem1.Checked = true;
            timesFasterToolStripMenuItem.Checked = false;
            normalToolStripMenuItem.Checked = false;
            timesSlowerToolStripMenuItem.Checked = false;
            timesSlowerToolStripMenuItem1.Checked = false;
        }

        private void normalToolStripMenuItem_Click(object sender, EventArgs e)// run at normal speed
        {
            procTimer = new Timer();
            procTimer.Interval = 1;
            normalToolStripMenuItem.Checked = true;
            timesFasterToolStripMenuItem.Checked = false;
            timesFasterToolStripMenuItem1.Checked = false;
            timesSlowerToolStripMenuItem.Checked = false;
            timesSlowerToolStripMenuItem1.Checked = false;
        }

        private void timesSlowerToolStripMenuItem_Click(object sender, EventArgs e)// run at 2 times slower speed
        {
            procTimer = new Timer();
            procTimer.Interval = 2;
            timesSlowerToolStripMenuItem.Checked = true;
            timesFasterToolStripMenuItem.Checked = false;
            timesFasterToolStripMenuItem1.Checked = false;
            normalToolStripMenuItem.Checked = false;
            timesSlowerToolStripMenuItem1.Checked = false;
        }

        private void timesSlowerToolStripMenuItem1_Click(object sender, EventArgs e)// run at 4 times slower speed
        {
            procTimer = new Timer();
            procTimer.Interval = 4;
            timesSlowerToolStripMenuItem1.Checked = true;
            timesFasterToolStripMenuItem.Checked = false;
            timesFasterToolStripMenuItem1.Checked = false;
            normalToolStripMenuItem.Checked = false;
            timesSlowerToolStripMenuItem.Checked = false;
        }

        private void toolStripButton14_Click_1(object sender, EventArgs e)
        {
            canrotate = false;
            myOGLView.changeOrtho(true);
            myOGLView.changeOthro();
            myOGLView.Changexrot(0);
            myOGLView.Changeyrot(0);
            myOGLView.Changezrot(0);
            myOGLView.Invalidate();
        }

        private void toolStripButton15_Click_1(object sender, EventArgs e)
        {
            canrotate = false;
            myOGLView.changeOrtho(true);
            myOGLView.changeOthro();
            myOGLView.Changexrot(-90);
            myOGLView.Changeyrot(0);
            myOGLView.Changezrot(0);
            myOGLView.Invalidate();
        }

        private void toolStripButton17_Click_1(object sender, EventArgs e)
        {
            canrotate = true;
            myOGLView.changeOrtho(false);
            myOGLView.changeOthro();
            myOGLView.Changexrot(0);
            myOGLView.Changeyrot(0);
            myOGLView.Invalidate();
        }

        private void toolStripButton16_Click_1(object sender, EventArgs e)
        {
            canrotate = false;
            myOGLView.changeOrtho(true);
            myOGLView.changeOthro();
            myOGLView.Changexrot(-90);
            myOGLView.Changeyrot(0);
            myOGLView.Changezrot(90);
            myOGLView.Invalidate();
        }

        private void toolStripButton8_Click_1(object sender, EventArgs e)
        {
            scale = scale + 0.01f;
            myOGLView.ChangeScale(scale);
            myOGLView.Invalidate();
        }

        private void toolStripButton12_Click_1(object sender, EventArgs e)
        {
            scale = scale - 0.01f;
            myOGLView.ChangeScale(scale);
            myOGLView.Invalidate();
        }

        private void toolStripButton18_Click(object sender, EventArgs e)
        {
            myOGLView.Changextrans(0);
            myOGLView.Changeytrans(0);
            xtrans = 0;
            ytrans = 0;
            myOGLView.Invalidate();
        }

        private void importCompNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\
            openFileDialog.Filter = "文本文件|*.*|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                watch.Start();

                if (this.Controls.Contains(myOGLView))
                {
                    this.Controls.Remove(myOGLView);
                }

                //myOGLView = null;
                string path = openFileDialog.FileName;
                //string path = @"f:\PointComp.txt";
                string[] file_content = File.ReadAllLines(path, Encoding.Default);

                E_PointFrame point_frame = new E_PointFrame(-1);
                float time = -1;

                for (int i = 0; i < file_content.Length; i++)
                {
                    string[] sArray = file_content[i].Split(' ');
                    //string[] sArraynext = file_content[i].Split(' ');

                    int id = 0;
                    float x = 0.0f;
                    float y = 0.0f;
                    float z = 0.0f;

                    if (sArray.Length == 2)  // time and nb_of_points
                    {
                        time = float.Parse(sArray[0]);
                        if (point_frame.getTime() != -1)
                        {
                            l_point_frames.Add(point_frame);
                            //lp_list.Add(newlist);
                            //newlist.Clear();
                        }
                        point_frame = new E_PointFrame(time);
                    }
                    else
                    {
                        id = int.Parse(sArray[0]);
                        x = float.Parse(sArray[1]);
                        y = float.Parse(sArray[2]);
                        z = float.Parse(sArray[3]);
                        point_frame.AddPoint(new E_Point(id, x, y, z));
                        //newlist.Add(new E_Point(id,x,y,z));
                    }
                }

                l_point_frames.Add(point_frame);
                point_frame = null;

                //lp_list.Add(newlist);
                //newlist.Clear();

                //            MessageBox.Show(point_list[30].z.ToString() + point_list[80].x.ToString() + point_list[100].y.ToString());
                //              MessageBox.Show(lp_list[0][0].x.ToString());
                watch.Stop();
                MessageBox.Show("已导入全部点坐标，用时 " + watch.ElapsedMilliseconds.ToString() + "ms");
                watch.Reset();

            }

        }

        private void importCompElementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\
            //openFileDialog.Filter = "文本文件|*.*|所有文件|*.*";
            //openFileDialog.RestoreDirectory = true;
            //openFileDialog.FilterIndex = 1;
            //if (openFileDialog.ShowDialog() == DialogResult.OK)
            //{
            //    watch.Start();

            //    //line_list.Clear();
            //    //line_count = 0;
            //    //test_count = 0;
            //    //dif_times = 0;
            //    if (this.Controls.Contains(myOGLView))
            //    {
            //        this.Controls.Remove(myOGLView);
            //    }

            //    //myOGLView = null;
            //    //string path = @"f:\LineComp.txt";
            //    string path = openFileDialog.FileName;
            //    string[] file_content = File.ReadAllLines(path, Encoding.Default);

            //    //List<E_Line> newlinelist = new List<E_Line>();
            //    E_LineFrame line_frame = new E_LineFrame(-1);

            //    string state = "0";
            //    float time = -1;

            //    for (int i = 0; i < file_content.Length; i++)
            //    {
            //        string[] sArray = file_content[i].Split(' ');

            //        int id = 0;
            //        int id1 = 0;
            //        int id2 = 0;

            //        if (sArray.Length == 1) // time or state
            //        {
            //            char c = sArray[0].ToCharArray()[0];
            //            if (c != '+' && c != '-') //time
            //            {
            //                time = float.Parse(sArray[0]);
            //                if (line_frame.getTime() != -1)
            //                {
            //                    l_line_frames.Add(line_frame);

            //                }
            //                line_frame = new E_LineFrame(time, line_frame);
            //                //ll_list.Add(newlinelist);
            //                //newlinelist.Clear();
            //            }
            //            else    //state
            //            {
            //                state = sArray[0];
            //            }

            //        }
            //        else        //line data, length = 3
            //        {
            //            id = int.Parse(sArray[0]);
            //            id1 = int.Parse(sArray[1]);
            //            id2 = int.Parse(sArray[2]);

            //            E_Line templine = new E_Line(id, id1, id2);

            //            if (state == "+1")
            //            {
            //                line_frame.AddLine(templine);
            //            }
            //            if (state == "-1")
            //            {
            //                line_frame.RemoveLine(templine);
            //            }
            //            if (state == "+0")
            //            {
            //                line_frame.ChangeLine(templine);
            //            }
            //        }
            //    }
            //    l_line_frames.Add(line_frame);

            //    watch.Stop();
            //    MessageBox.Show("element load! time used:" + watch.ElapsedMilliseconds.ToString() + " ms");
            //    watch.Reset();

            //    isLoadComp = true;

            //    //myOGLView = new MyOGLControl(lp_list[0], ll_list[0], area_list, solid_list);
            //    myOGLView = new MyOGLControl(l_point_frames[0], l_line_frames[0], area_list, solid_list);

            //    ((Control)this.myOGLView).MouseDown += new MouseEventHandler(myOGLView_MouseDown);
            //    ((Control)this.myOGLView).MouseMove += new MouseEventHandler(myOGLView_MouseMove);
            //    ((Control)this.myOGLView).MouseUp += new MouseEventHandler(myOGLView_MouseUp);

            //    //myOGLView.Anchor = AnchorStyles.Top;
            //    myOGLView.Dock = DockStyle.Fill;

            //    myOGLView.BringToFront();
            //    myOGLView.Parent = this;
            //    myOGLView.Name = "Kimi";
            //    myOGLView.Visible = true;
            //    //  myOGLView.CreateControl();
            //    //  myOGLView.Invalidate();
            //    this.Controls.Add(myOGLView);
            //    RToolStripMenuItem.Enabled = true;
            //    toolStripButton8.Enabled = true;
            //    toolStripButton12.Enabled = true;
            //    toolStripButton5.Enabled = true;
            //    toolStripButton13.Enabled = true;
            //    toolStripSplitButton1.Enabled = true;
            //    toolStripButton14.Enabled = true;
            //    toolStripButton15.Enabled = true;
            //    toolStripButton16.Enabled = true;
            //    toolStripButton17.Enabled = true;
            //    toolStripButton18.Enabled = true;
            //}
        }

        private void compressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process p = Process.Start("DataComp.exe");

            //ShellExecute(NULL,"open","DataComp.exe",NULL,NULL,SW_SHOWNORMAL);
        }

        private void NodeComp(String filepath)
        {
            // read file into memory
            String path = filepath;
            StreamReader sr = new StreamReader(path);
            String file_content;

            // variables
            String sOldTime = "-1";
            E_PointFrame tempFrame_point = null;

            // create or overwrite the out file
            int dot = path.LastIndexOf(".");
            String pathout = path.Substring(0, dot) + "Comp" + ".txt";
            FileStream outfs = new FileStream(pathout, FileMode.Create, FileAccess.Write);
            outfs.Close();
            StreamWriter sw = new StreamWriter(pathout, true);

            int iNbNodeValid = 0;
            //String sOldTime = "0.0000000000000000e+000";

            while ((file_content = sr.ReadLine()) != null)
            {
                String sContent;
                // remove the first 2 spaces
                sContent = file_content.Trim();
                // replace 2 spaces by one
                sContent = sContent.Replace("  ", " ");

                // saperate the string by space, 5 columns: Time id x y z
                string[] sArray = sContent.Split(' ');

                // refresh time and nb of node
                if (sOldTime != sArray[0])
                {
                    if (tempFrame_point != null)
                    {
                        // write time and nb of nodes into file NodeComp
                        sw.WriteLine(tempFrame_point.getTime().ToString("0.#####") + " " + iNbNodeValid);

                        // write nodes into file
                        ArrayList akeys = new ArrayList(tempFrame_point.m_points.Keys); //get key of hashtable
                        akeys.Sort(); //按字母顺序进行排序 
                        foreach (int skey in akeys)
                        {
                            E_Point tp = (E_Point)tempFrame_point.m_points[skey];
                            sw.WriteLine(tp.id + " " + tp.x.ToString("0.##########") + " " + tp.y.ToString("0.##########") + " " + tp.z.ToString("0.##########"));
                        }
                    }

                    // initial the temporary frame
                    tempFrame_point = new E_PointFrame(g_method.StringToF(sArray[0]));

                    // reset 
                    sOldTime = sArray[0];
                    iNbNodeValid = 0;
                }

                // create a temprary point 
                E_Point tempPoint = new E_Point(g_method.StringToI(sArray[1]),
                    g_method.StringToF(sArray[2]), g_method.StringToF(sArray[3]), g_method.StringToF(sArray[4]));

                // test if the point is valid or not 
                if (tempPoint.x != 0 || tempPoint.y != 0 || tempPoint.z != 0)
                {
                    // add points into tempframe
                    tempFrame_point.AddPoint(tempPoint);
                    iNbNodeValid++;
                }
            }

            // save the last point-frame into file
            if (tempFrame_point != null)
            {
                // write time and nb of nodes into file NodeComp
                sw.WriteLine(g_method.StringToF(sOldTime).ToString("0.#####") + " " + iNbNodeValid);

                // write nodes into file
                ArrayList akeys = new ArrayList(tempFrame_point.m_points.Keys); //别忘了导入System.Collections 
                akeys.Sort(); //按字母顺序进行排序 
                foreach (int skey in akeys)
                {
                    E_Point tp = (E_Point)tempFrame_point.m_points[skey];
                    sw.WriteLine(tp.id + " " + tp.x.ToString("0.##########") + " " + tp.y.ToString("0.##########") + " " + tp.z.ToString("0.##########"));
                }
            }

            sr.Close();
            sw.Close();
        }

        private void ElementComp(String filepath)
        {
            // read file into memory
            String path = filepath;
            StreamReader sr = new StreamReader(path);
            String file_content;

            // variables
            String sOldTime = "-1";
            E_LineFrame currentLineFrame = null;
            E_LineFrame lastLineFrame = null;

            // create or overwrite the out file
            int dot = path.LastIndexOf(".");
            String pathout = path.Substring(0, dot) + "Comp" + ".txt";
            FileStream outfs = new FileStream(pathout, FileMode.Create, FileAccess.Write);
            outfs.Close();
            StreamWriter sw = new StreamWriter(pathout, true);

            while ((file_content = sr.ReadLine()) != null)
            {
                String sContent;
                // remove the first 2 spaces
                sContent = file_content.Trim();
                // replace 2 spaces by one
                sContent = sContent.Replace("  ", " ");

                // saperate the string by space, 4 columns: Time ID_line ID_a1 ID_a2
                string[] sArray = sContent.Split(' ');

                // refresh time and nb of node
                if (sOldTime != sArray[0])
                {
                    // compare two line_frames
                    if (currentLineFrame != null)
                    {
                        if (lastLineFrame == null)
                        {
                            lastLineFrame = new E_LineFrame(-1);
                        }
                        currentLineFrame.compareLineFrame(lastLineFrame);

                        // write time into file LineComp
                        sw.WriteLine(currentLineFrame.m_timestamp.ToString("0.#####"));

                        // write lines into file
                        if (currentLineFrame.m_line_added.Count != 0)
                        {
                            sw.WriteLine("+1");
                            foreach (E_Line tl in currentLineFrame.m_line_added)
                            {
                                sw.WriteLine(tl.id + " " + tl.p1id + " " + tl.p2id);
                            }
                        }
                        if (currentLineFrame.m_line_removed.Count != 0)
                        {
                            sw.WriteLine("-1");
                            foreach (E_Line tl in currentLineFrame.m_line_removed)
                            {
                                sw.WriteLine(tl.id + " " + tl.p1id + " " + tl.p2id);
                            }
                        }
                        if (currentLineFrame.m_line_changed.Count != 0)
                        {
                            sw.WriteLine("+0");
                            foreach (E_Line tl in currentLineFrame.m_line_changed)
                            {
                                sw.WriteLine(tl.id + " " + tl.p1id + " " + tl.p2id);
                            }
                        }

                        // refresh last frame
                        lastLineFrame = currentLineFrame;
                    }

                    // initial a new frame of line
                    currentLineFrame = new E_LineFrame(g_method.StringToF(sArray[0]));

                    // reset 
                    sOldTime = sArray[0];

                }

                // create a temprary line 
                E_Line templine = new E_Line(g_method.StringToI(sArray[1]),
                    g_method.StringToI(sArray[2]), g_method.StringToI(sArray[3]));

                // add lines into tempframe
                currentLineFrame.AddLine(templine);

            }

            // save the last line frame
            if (currentLineFrame != null)
            {
                if (lastLineFrame == null)
                {
                    lastLineFrame = new E_LineFrame(-1);
                }
                currentLineFrame.compareLineFrame(lastLineFrame);

                // write time into file LineComp
                sw.WriteLine(currentLineFrame.m_timestamp.ToString("0.#####"));

                // write lines into file
                if (currentLineFrame.m_line_added.Count != 0)
                {
                    sw.WriteLine("+1");
                    foreach (E_Line tl in currentLineFrame.m_line_added)
                    {
                        sw.WriteLine(tl.id + " " + tl.p1id + " " + tl.p2id);
                    }
                }
                if (currentLineFrame.m_line_removed.Count != 0)
                {
                    sw.WriteLine("-1");
                    foreach (E_Line tl in currentLineFrame.m_line_removed)
                    {
                        sw.WriteLine(tl.id + " " + tl.p1id + " " + tl.p2id);
                    }
                }
                if (currentLineFrame.m_line_changed.Count != 0)
                {
                    sw.WriteLine("+0");
                    foreach (E_Line tl in currentLineFrame.m_line_changed)
                    {
                        sw.WriteLine(tl.id + " " + tl.p1id + " " + tl.p2id);
                    }
                }
            }

            // close the file streams
            sr.Close();
            sw.Close();
        }
     
    }
}
